home *** CD-ROM | disk | FTP | other *** search
- ;; Note: this is too recursive for the default MM [op] stack(s).
-
- ;; Ackerman's function
- ;; (A 0 0) => 1
- ;; (A 0 1) => 2
- ;; (A 0 2) => 3
- ;; (A 1 0) => 2
- ;; (A 1 1) => 3
- ;; (A 3 6) => 509
- (defun A (int x y)
- {
- (case
- (== x 0) (+ y 1)
- (== y 0) (A (- x 1) 1)
- TRUE (A (- x 1) (A x (- y 1)))
- )
- })
-
- (const NUMBER 0x03)
- (defun MAIN
- {
- (msg (A (convert-to NUMBER (ask "x = "))(convert-to NUMBER (ask "y = "))))
- })
-
-
- ; /* Ackerman's function in C */
- ; /* Example "ack 3 6" => 509 */
- ; main(argc,argv) char *argv[];
- ; {
- ; int x,y, i;
-
- ; x = atoi(argv[1]); y = atoi(argv[2]);
- ; i = A(x,y);
- ; printf("ackerman's(%d, %d): %d\n", x,y,i);
- ; }
-
- ; A(x,y) int x,y;
- ; {
- ; if (x == 0) return (++y);
- ; if (y == 0) return (A(--x,1));
- ; return (A(--x,A(x,--y)));
- ; }
-